package com.eastfair.security.config;

import com.eastfair.security.properties.SecurityProperties;
import com.eastfair.security.aspect.UrlSecurityPreAuthAspect;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;

/**
 * 权限认证配置类
 *
 * @author ligang
 * @date 2020年03月29日22:34:45
 */
@Order
@AllArgsConstructor
@EnableConfigurationProperties({SecurityProperties.class})
//@Configuration
public class SecurityConfiguration {
    private final SecurityProperties securityProperties;

    @Bean
    @ConditionalOnProperty(prefix = SecurityProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
    public UrlSecurityPreAuthAspect uriSecurityPreAuthAspect() {
        return new UrlSecurityPreAuthAspect();
    }


//    @Bean
//    @ConditionalOnProperty(prefix = SecurityProperties.PREFIX, name = "enabled", havingValue = "true", matchIfMissing = true)
//    public UrlSecurityPreAuthAspect uriSecurityPreAuthAspect(VerifyAuthFunction verifyAuthFunction) {
//        return new UrlSecurityPreAuthAspect(verifyAuthFunction);
//    }

//    @Bean("fun")
//    @ConditionalOnMissingBean(VerifyAuthFunction.class)
//    public VerifyAuthFunction getVerifyAuthFunction(UserResolverService userResolverService) {
//        return new VerifyAuthFunction(userResolverService, securityProperties);
//    }

}
